#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"

bool isValid(char * s)
{
	Stack1 st;
	StackInit(&st);
	while (*s)
	{
		if (*s == '{' || *s == '(' || *s == '[')
		{
			StackPush(&st, *s);
		}

		else
		{
			if (StackEmpty(&st))
			{
				StackDestroy(&st);
				return false;
			}

			char c = StackTop(&st);
			StackPop(&st);
			if ((*s == '{'&& c != '}') ||
				(*s == '['&& c != ']') ||
				(*s == '('&& c != ')'))
			{
				StackDestroy(&st);
				return false;
			}
		}
		s++;
	}

	StackDestroy(&st);
	return true;
}

void test()
{
	char s[] = "(]";
	int ret = isValid(s);
	printf("%d\n", ret);
}

int main()
{

	test();
	return 0;
}